import { createStore } from 'vuex'
import { login, logout } from "@/api/user"

export default createStore({
    state: {
        isLogin: false
    },
    mutations: {
        CHANGE_LOGIN_STATUS(state, status) {
            state.isLogin = status
        }
    },
    actions: {
        async login({ commit }) {
            try {
                await login()
                commit('CHANGE_LOGIN_STATUS', true)
            } catch (e) {
                return e
            }
        },
        async logout({ commit }) {
            try {
                await logout()
                commit('CHANGE_LOGIN_STATUS', false)
            } catch (e) {
                return e
            }
        }
    },
    modules: {}
})
